package File_;

import org.junit.jupiter.api.Test;

import java.io.File;
import java.io.IOException;

/**
 * @author 培培
 * @condition 努力学习中
 */
public class FileCreate {
    public static void main(String[] args) {

    }

    //方式1 new File(String pathname)
    @Test
    public void create01(){
        String filePath = "D:\\news1.txt";
        File file = new File(filePath);

        try {
            file.createNewFile();
            System.out.println("创建文件成功");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    //第二种方式 new File(File parent,String child) ，根据父目录文件 + 子路径构建
    //D:\\news2.txt
    @Test
    public void create02(){
        File parentFile = new File("D:\\");
        String fileName = "news2.txt";
        File file = new File(parentFile, fileName);

        try {
            file.createNewFile();
            System.out.println("创建成功~");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    //第三种方式 new File(String parent,String child) ，根据父目录文件 + 子路径构建
    //D:\\news3.txt
    @Test
    public void create03(){
        String parentFile = "D:\\";
        String fileName = "news3.txt";
        File file = new File(parentFile, fileName);

        try {
            file.createNewFile();
            System.out.println("创建成功~");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
